package com.accompany.fragment.my.activity;


import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import com.accompany.R;
import com.accompany.api.category.UnBindBlankCardCategory;
import com.accompany.api.presenter.UnBindBlankCardPresenter;
import com.accompany.base.BaseActivity;
import com.accompany.base.BaseBean;
import com.accompany.dialog.UnbindCardDialog;
import com.accompany.main.ConstantStaticUrl;
import com.accompany.utils.BankCardUtils;
import com.accompany.utils.FullScreenUtils;
import com.accompany.utils.SPUtils;
import com.accompany.utils.ToastUtil;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 信息说明:解除绑定银行卡界面
 * company: 兰州丰荣信息科技有限公司
 * 创建时间: on 2022/3/11 10 ：24
 * 项目名称：yuanban
 */
public class UnBindCardActivity extends BaseActivity implements View.OnClickListener, UnBindBlankCardCategory.View {

    @BindView(R.id.base_title)
    TextView mTitleMsg;

    @BindView(R.id.cardno)
    TextView cardno;
    private UnbindCardDialog dialog;
    private String bankName, bankCard,id;
    private  UnBindBlankCardCategory.Presenter mPresenter;
    private String mToken;
    private UnBindCardActivity activity;

    @Override
    public int getLayoutId() {
        return R.layout.activity_unbind_card;
    }

    @Override
    public void initLayoutView() {
        activity = UnBindCardActivity.this;
        mTitleMsg.setText("解绑银行卡");
        FullScreenUtils.getInstance().fullScreen(UnBindCardActivity.this, true);
        bankName = getIntent().getStringExtra("bankName");
        bankCard = getIntent().getStringExtra("bankCard");
        id = getIntent().getStringExtra("id");
        if (!TextUtils.isEmpty(bankCard)) {
            cardno.setText(BankCardUtils.handleBankCardNum(bankCard));
        }
        mToken = (String) SPUtils.get(activity, ConstantStaticUrl.mToken, "");
        mPresenter = new UnBindBlankCardPresenter(activity);
        SetPersenter(mPresenter);


    }

    @OnClick({R.id.base_back, R.id.unbind_card})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.base_back:
                finishWitchAnimation();
                break;
            case R.id.unbind_card:
                SelectUnBindCard();
                break;
        }
    }

    private void SelectUnBindCard() {
        dialog = new UnbindCardDialog(UnBindCardActivity.this);
        dialog.show();
        dialog.findViewById(R.id.zan_bind).setOnClickListener(this);
        dialog.findViewById(R.id.submit_unding).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.zan_bind://暂不解绑
                dialog.dismiss();
                break;
            case R.id.submit_unding://立即解绑
                mPresenter.unBindCard(mToken,id);
                dialog.dismiss();
                break;
        }
    }


    @Override
    public void unBindCard(BaseBean baseBean) {
        if (baseBean.getCode()==ConstantStaticUrl.SUCCESS_CODE){
            ToastUtil.showToastSUCCESS(activity,"解绑成功");
            finish();
        }else {
            ToastUtil.showToastSUCCESS(activity,"操作失败");
        }
    }

    @Override
    public void SetPersenter(Object persenter) {

    }

    @Override
    public void OnShowErrorMsg(String mErrorMsg) {
        ToastUtil.showToastERROR(activity,mErrorMsg);
    }
}
